<template>
  <!--核收开窗-->
  <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :title="dialogTitle"
    :visible.sync="dialogCollectVisible" @close="CollectClose()" v-if="dialogCollectVisible" width="1000px">
    <div style="width:100%;text-align:right">
      <table style="cellspacing: 5px" class="collectbtntable">
        <tr>
          <!-- <td style="width:500px"></td> -->
          <td style="text-align:left">
            <el-button @click="CollectMove(0)" style="width:80px;margin-bottom: 5px">上一个</el-button>
          </td>
          <td>
            <el-button @click="CollectMove(1)" style="width:80px;margin-bottom: 5px">下一个</el-button>
          </td>
          <td>
            <el-button @click="PrintBarcode()" style="width:80px;margin-bottom: 5px">打印</el-button>
          </td>
          <td style="text-align:left">
            <el-button @click="CollectDel()" style="width:80px;margin-bottom: 5px">删除</el-button>
          </td>
          <td>
            <el-button @click="CollectClose()" style="width:80px;margin-bottom: 5px" type="primary">退出</el-button>
          </td>
          <!--无该选项或者有该选项但是勾上的，默认值是勾上 -->
          <td style="margin-bottom: 5px" v-if="Options.batchinputquickmodel == '' || Options.batchinputquickmodel == '1'">
            <el-checkbox v-model="isasync" style="padding-right: 5px">快扫模式</el-checkbox>
          </td>
          <td style="text-align:left">
            <el-checkbox v-model="alertcannoitem" style="padding-right: 5px">弹窗提醒本报告单元不能完成且未上机的申请项目</el-checkbox>
          </td>
          <td style="text-align:left" v-if="Options.batchinputmustconfirm == '1'">
            <el-checkbox v-model="collectmustconfirm">核收前必须确认</el-checkbox>
          </td>
          <td style="text-align:left" v-if="Options.batchinputdaymustclick == '1'">
            <el-checkbox v-model="onlyclickinputday">日期禁止手输</el-checkbox>
          </td>
          <!-- <td>
                      <el-button style="width:80px;margin-right: 5px;margin-bottom: 5px">打印</el-button>
                  </td> -->
        </tr>
      </table>
    </div>
    <table>
      <tr :class="DateBackGround()">
        <td style="font-weight:bold;font-size: 14px">
          标本编号
        </td>
        <td>
          <el-input v-model="collectsampleno" @keyup.enter.native="$refs.collectbarcodeinput.focus()" ref="collectspec"
            class="collectspec" :disabled="useautobarcode" @change="SampleNoChange()"></el-input>
        </td>
        <td>
          核收报告单元
        </td>
        <td>
          <rm-ddl-rptunit :prgno="PRGNO" defaultflag="1" v-model="collectrptunitid" width="160px" :clearable="false"
            @change="collectrptunitidchange" ref="collectrptunit"></rm-ddl-rptunit>
        </td>
        <td>
          标本日期
        </td>
        <td>
          <el-date-picker v-model="collectselectdate" value-format="yyyy-MM-dd HH:mm:ss" style="width:100%"
            :picker-options="pickerOptions" :clearable="false" @focus="forbidinput"></el-date-picker>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;font-size: 14px">
          条形码
        </td>
        <td>
          <div class="el-input el-input--small">
            <input type="text" value="" :placeholder="collectbarcodeholder" class="el-input__inner"
              @keydown.enter="CollectBarcode($event)" @focus="$refs.collectbarcodeinput.select()"
              ref="collectbarcodeinput" id="collectbarcodeinput">
          </div>
        </td>
        <td>指定标本类型</td>
        <td>
          <rm-ddl-common datatype="specimen" dataname="标本类型" width="160px" :instrid="rptunitid"
            v-model="CollectSpecType"></rm-ddl-common>
        </td>
        <td colspan="2" style="text-align: left">
          <el-checkbox v-model="showseq" @change="showseqChange">显示核收序号</el-checkbox>
          <span style="color:purple;font-size:16px;margin-left: 5px;margin-right: 5px">共核收{{ CollectNum }}个</span>
          <span style="color:red;font-size:16px" v-show="CollectErrNum > 0">共{{ CollectErrNum }}条错误消息</span>
        </td>
      </tr>
      <tr v-show="multiplereportflag" v-for="item in previousPatients" :key="item.sampleno">
        <td colspan="8" style="text-align:left">
          <div style="word-wrap:break-word;word-break:break-all;white-space:normal;">
            <span class="top-sample-info" v-show="item.hasOwnProperty('barcode')">【{{ item.sampleno }}】</span>
            <span class="top-sample-info" v-show="item.hasOwnProperty('barcode')">【{{ item.pat_name }}】</span>
            <span class="top-sample-info" v-show="item.hasOwnProperty('barcode')">【{{ item.pat_sexname }}】</span>
            <span class="top-sample-info" v-show="item.hasOwnProperty('barcode')">【{{ item.req_reason }}】</span>
            <span class="top-sample-info" v-show="item.hasOwnProperty('barcode')">【{{ item.barcode }}】</span>
          </div>
        </td>
      </tr>
      <tr v-show="!multiplereportflag">
        <td colspan="8" style="text-align:left">
          <div style="margin-top: 10px;margin-bottom: 5px;word-wrap:break-word;word-break:break-all;white-space:normal;">
            <span class="top-sample-info"
              v-show="previousPatient.hasOwnProperty('barcode') && useautobarcode">【{{ previousPatient.sampleno }}】</span>
            <span class="top-sample-info"
              v-show="previousPatient.hasOwnProperty('barcode')">【{{ previousPatient.pat_name }}】</span>
            <span class="top-sample-info"
              v-show="previousPatient.hasOwnProperty('barcode')">【{{ previousPatient.pat_sexname }}】</span>
            <span class="top-sample-info"
              v-show="previousPatient.hasOwnProperty('barcode')">【{{ previousPatient.req_reason }}】</span>
            <span class="top-sample-info"
              v-show="previousPatient.hasOwnProperty('barcode')">【{{ previousPatient.barcode }}】</span>
          </div>
        </td>
      </tr>
    </table>
    <!-- <table>
          <tr>
              <td style="width:580px">
                  <table style="width:100%">
                      <tr>
                          <td>
                              标本日期
                          </td>
                          <td colspan="3">
                              <el-date-picker v-model="collectselectdate" value-format="yyyy-MM-dd HH:mm:ss" style="width:100%" :clearable="false"></el-date-picker>
                          </td>
                          <td>
                              报告单元
                          </td>
                          <td>
                              <rm-ddl-rptunit :prgno="PRGNO" defaultflag="1" v-model="collectrptunitid" width="160px" :clearable="false" @change="collectrptunitidchange"></rm-ddl-rptunit>
                          </td>
                      </tr>
                      <tr>
                          <td style="font-weight:bold;font-size: 14px">
                              标本编号
                          </td>
                          <td colspan="3">
                              <el-input v-model="collectsampleno" @keyup.enter.native="$refs.collectbarcodeinput.focus()" ref="collectspec"></el-input>
                          </td>
                          <td style="font-weight:bold;font-size: 14px">
                              条形码
                          </td>
                          <td>
                              <div class="el-input el-input--small">
                                  <input type="text" value="" :placeholder="collectbarcodeholder" class="el-input__inner" @keydown.enter="CollectBarcode($event)" @focus="$refs.collectbarcodeinput.select()" ref="collectbarcodeinput" id="collectbarcodeinput">
                              </div>
                          </td>
                      </tr>
                      <tr>
                          <td></td>
                          <td colspan="3"></td>
                          <td>指定标本类型</td>
                          <td>
                              <rm-ddl-common datatype="specimen" dataname="标本类型" width="160px" :instrid="rptunitid" v-model="CollectSpecType"></rm-ddl-common>
                          </td>
                      </tr>
                      <tr>
                          <td colspan="4" style="text-align:left"><span>上一标本信息</span></td>
                      </tr>
                      <tr>
                          <td style="font-weight:bold;font-size: 12px">标本号</td>
                          <td colspan="3">
                              <el-input v-model="previousPatient.sampleno" readonly></el-input>
                          </td>
                          <td style="font-weight:bold;font-size: 12px">条形码</td>
                          <td>
                              <el-input v-model="previousPatient.barcode" readonly></el-input>
                          </td>
                      </tr>
                      <tr>
                          <td>姓名</td>
                          <td colspan="3">
                              <el-input v-model="previousPatient.pat_name" readonly></el-input>
                          </td>
                          <td>科室</td>
                          <td>
                              <el-input v-model="previousPatient.req_deptnoname" readonly></el-input>
                          </td>
                      </tr>
                      <tr>
                          <td>性别</td>
                          <td>
                              <el-input v-model="previousPatient.pat_sexname" readonly></el-input>
                          </td>
                          <td>年龄</td>
                          <td>
                              <el-input v-model="previousPatient.pat_age" readonly></el-input>
                          </td>
                          <td>床号</td>
                          <td>
                              <el-input v-model="previousPatient.req_bedno" readonly></el-input>
                          </td>
                      </tr>
                      <tr>
                          <td>申请项目</td>
                          <td colspan="5">
                              <el-input v-model="previousPatient.req_reason" readonly></el-input>
                          </td>
                      </tr>
                  </table>
              </td>
              <td style="vertical-align:top">
                  <table>
                      <tr>
                          <td>
                              <el-button @click="CollectMove(0)" style="width:80px;margin-right: 5px;margin-bottom: 5px">上一个</el-button>
                          </td>
                          <td>
                              <el-button style="width:80px;margin-right: 5px;margin-bottom: 5px">打印</el-button>
                          </td>
                          <td style="margin-bottom: 5px">
                              <el-checkbox v-model="isasync">快扫模式</el-checkbox>
                          </td>
                      </tr>
                      <tr>
                          <td>
                              <el-button @click="CollectMove(1)" style="width:80px;margin-right: 5px;margin-bottom: 5px">下一个</el-button>
                          </td>
                          <td>
                              <el-button @click="CollectDel()" style="width:80px;margin-bottom: 5px">删除</el-button>
                          </td>
                          <td style="text-align: left;">
                              <el-button @click="CollectClose()" style="width:80px;margin-bottom: 5px">退出</el-button>
                          </td>
                      </tr>
                  </table>
                  <table>
                      <tr>
                          <td style="text-align:left" colspan="2">
                              <el-checkbox>复制标签<el-input v-model="copylabellty" size="mini" style="width:40px"></el-input>份</el-checkbox>
                          </td>
                      </tr>
                      <tr>
                          <td>

                          </td>
                      </tr>
                      <tr>
                          <td style="text-align:left"></td>
                          <td>
                              <el-button style="margin-left:25px">标签打印</el-button>
                          </td>
                      </tr>
                      <tr>
                          <td style="text-align:left" colspan="2">
                              <el-checkbox>打印申请单</el-checkbox>
                          </td>
                      </tr>
                      <tr>
                          <td style="text-align:left" colspan="2">
                              <el-checkbox v-model="alertcannoitem">弹窗提醒本报告单元不能完成且未上机的申请项目</el-checkbox>
                          </td>
                      </tr>
                      <tr>
                          <td style="text-align:left">
                              <span style="color:purple;font-size:20px">本次共核收{{CollectNum}}个</span>
                          </td>
                      </tr>
                      <tr>
                          <td style="text-align:left">
                              <span style="color:red;font-size:20px" v-show="CollectErrNum>0">共{{CollectErrNum}}条错误消息未处理</span>
                          </td>
                      </tr>
                  </table>
              </td>
          </tr>
      </table> -->
    <div style="height: 400px">
      <rm-layout-right splitcolor="#FFFFFF" movingcolor="#66CCFF" :splitwidth="batchinputshownoseg ? 5 : 0"
        :fixsize="batchinputshownoseg ? 300 : 0" :canDrag="batchinputshownoseg">
        <template v-slot:fix>
          <div v-if="batchinputshownoseg">
            <vxe-table :data.sync="tableDataBatch" @cell-dblclick="CollectDblClick" :sort-config="{ trigger: 'cell' }"
              :keyboard-config="keyConfig" height="397px" highlight-current-row highlight-hover-row ref="xTableBatch"
              resizable highlight-hover-column show-header-overflow="tooltip" show-overflow="tooltip"
              header-align="center" size="mini" stripe width="auto">
              <vxe-table-column :field="item.field" :title="item.title" :key="item.field" :width="item.width"
                v-for="item in tableColumnBatch"></vxe-table-column>
            </vxe-table>
          </div>
        </template>
        <div style="height:100%">
          <vxe-table :data.sync="MasterDataDisplay" :sort-config="{ trigger: 'cell' }"
            :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true }" :mouse-config="{ selected: true }"
            :select-config="selectConfig" :keyboard-config="keyConfig" border :span-method="colspanMethod" height="auto"
            highlight-current-row highlight-hover-row ref="xTableCollect" resizable highlight-hover-column
            show-header-overflow="tooltip" show-overflow="tooltip" header-align="center" align="center" size="mini" stripe
            width="auto" :row-class-name="xTableCollect_rowClass" @cell-click="RowClick"
            @cell-dblclick="xTableCollect_dbclick">
            <vxe-table-column type="selection" width="30px"></vxe-table-column>
            <vxe-table-column v-if="showseq" title="No." width="40">
              <template v-slot="{ rowIndex }">
                <span v-if="Options.showorderasc == '1'">{{ rowIndex + 1 }}</span>
                <span v-else>{{ MasterDataDisplay.length - rowIndex }}</span>
              </template>
            </vxe-table-column>
            <vxe-table-column field="sampleno" title="标本编号" key="sampleno" width="60px" sortable
              :sort-width="20"></vxe-table-column>
            <vxe-table-column field="barcode" title="条码号" key="barcode" width="100px"></vxe-table-column>
            <vxe-table-column field="emer_flag" title="急" key="emer_flag" width="30px" sortable>
              <template v-slot="{ row }">
                <span style="color:red" v-if="row.emer_flag > 0">急</span>
              </template>
            </vxe-table-column>
            <vxe-table-column field="pat_name" title="病人" key="pat_name" width="60px" sortable>
              <template v-slot="{ row }">
                <div class="parent-row" v-if="row.sflag == -1 || row.sflag == 2">
                  <span class="parent-row-name">{{ row.pat_name }}</span>
                </div>
                <div v-else>{{ row.pat_name }}</div>
              </template>
            </vxe-table-column>
            <vxe-table-column field="pat_no" title="病人号" key="pat_no" width="100px"></vxe-table-column>
            <vxe-table-column field="pat_typecodename" title="病人类型" key="pat_typecodename"
              width="60px"></vxe-table-column>
            <vxe-table-column field="specimen_codename" title="标本类型" key="specimen_code" width="80px"
              sortable></vxe-table-column>
            <vxe-table-column field="req_reason" title="申请项目" key="req_reason" width="200px" align="left"
              header-align="center"></vxe-table-column>
            <vxe-table-column field="req_deptnoname" title="科室" key="req_deptno" width="120px"
              sortable></vxe-table-column>
            <vxe-table-column field="req_bedno" title="床号" key="req_bedno" width="60px" sortable></vxe-table-column>
          </vxe-table>
        </div>

      </rm-layout-right>
      <!-- <table style="width:100%">
              <tr>
                  <td>
                      <div :style="{ width: batchinputshownoseg?'480px':'840px' }">
                          <vxe-table :data.sync="MasterDataDisplay" :sort-config="{trigger: 'cell'}" :edit-config="{trigger: 'click', mode: 'cell',showStatus: true}" :mouse-config="{selected: true}" :select-config="selectConfig" :keyboard-config="keyConfig" border :span-method="colspanMethod" height="400px" highlight-current-row highlight-hover-row ref="xTableCollect" resizable highlight-hover-column show-header-overflow="tooltip" show-overflow="tooltip" header-align="center" align="center" size="mini" stripe width="auto" :row-class-name="xTableCollect_rowClass" @cell-click="RowClick" @cell-dblclick="xTableCollect_dbclick">
                              <vxe-table-column type="selection" width="30px"></vxe-table-column>
                              <vxe-table-column field="sampleno" title="标本编号" key="sampleno" width="60px"></vxe-table-column>
                              <vxe-table-column field="barcode" title="条码号" key="barcode" width="100px"></vxe-table-column>
                              <vxe-table-column field="emer_flag" title="急" key="emer_flag" width="30px">
                                  <template v-slot="{ row }">
                                      <span style="color:red" v-if="row.emer_flag>0">急</span>
                                  </template>
                              </vxe-table-column>
                              <vxe-table-column field="pat_name" title="病人" key="pat_name" width="60px">
                                  <template v-slot="{ row }">
                                      <div class="parent-row" v-if="row.sflag == -1 || row.sflag == 2">
                                          <span class="parent-row-name">{{row.pat_name}}</span>
                                      </div>
                                      <div v-else>{{row.pat_name}}</div>
                                  </template>
                              </vxe-table-column>
                              <vxe-table-column field="pat_no" title="病人号" key="pat_no" width="100px"></vxe-table-column>
                              <vxe-table-column field="specimen_codename" title="标本类型" key="specimen_code" width="80px"></vxe-table-column>
                              <vxe-table-column field="req_reason" title="申请项目" key="req_reason" width="200px" align="left" header-align="center"></vxe-table-column>
                              <vxe-table-column field="req_deptnoname" title="科室" key="req_deptno" width=120px></vxe-table-column>
                              <vxe-table-column field="req_bedno" title="床号" key="req_bedno" width="60px"></vxe-table-column>
                          </vxe-table>
                      </div>
                  </td>
                  <td v-if="batchinputshownoseg">
                      <div style="width:350px">
                          <vxe-table :data.sync="tableDataBatch" @cell-dblclick="CollectDblClick" :sort-config="{trigger: 'cell'}" :keyboard-config="keyConfig" height="400px" highlight-current-row highlight-hover-row ref="xTableBatch" resizable highlight-hover-column show-header-overflow="tooltip" show-overflow="tooltip" header-align="center" size="mini" stripe width="auto">
                              <vxe-table-column :field="item.field" :title="item.title" :key="item.field" :width="item.width" v-for="item in tableColumnBatch"></vxe-table-column>
                          </vxe-table>
                      </div>
                  </td>
              </tr>
          </table> -->
    </div>
  </el-dialog>
</template>

<script>
import XE from "xe-utils";
export default {
  name: "rmlabreportcollect",
  data() {
    return {
      PRGNO: "",
      //是否异步处理方式
      isasync: false,
      showseq: true,//显示核收序号
      pickerOptions: {
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", XE.toDateString(new Date(), "yyyy-MM-dd 00:00:00"));
            },
          },
        ],
      }, //日期配置将时间切换到当天
      rptunitid: 0,
      BeforePatient: {},
      dialogCollectVisible: false,
      dialogTitle: "",
      collectselectdate: "",
      collectrptunitid: 0,
      collectsampleno: "1",
      CollectSpecType: "",
      previousPatient: {},
      previousPatients: [],
      temppreviousPatient: {},
      temppreviousPatients: {},
      copylabellty: "1",
      alertcannoitem: false,
      CollectNum: 0,
      CollectErrNum: 0,
      batchinputshownoseg: false,
      useautobarcode: false,
      MasterData: [],
      MasterDataDisplay: [],
      //主数据异步同步标志
      MasterDataSyncFlag: false,
      selectConfig: { tigger: "row" },
      keyConfig: {
        isDel: true,
        isTab: true,
        isEdit: true,
      },
      batchbarcodeonlytoday: "",
      collectbarcodeholder: "请扫描条码",
      tableColumnBatch: [],
      tableDataBatch: [],
      //扫码后台进程运行标志
      timeoutrunning: false,
      lasttxtbarcode: "",
      Options: {}, //选项
      collectmustconfirm: true, //提醒模式
      onlyclickinputday: false,//只能点击输入日期
      multiplereportflag: false, //返回多个标本号时
    };
  },
  watch: {
    isasync(val) {
      this.$tool.setLocalConfig("lis310_async", val ? "Y" : "N");
      if (val) {
        this.SetBarCodeInputReadonlyOff();
      }
    },
    MasterData(val) {
      //异步时，一旦主数据变化，启动可延迟处理
      var that = this;
      if (!that.timeoutrunning) {
        that.timeoutrunning = true;
        setTimeout(() => {
          that.DealBarCode(that);
        }, 100);
      }

      that.CollectNum = that.MasterData.length;

      if (!that.MasterDataSyncFlag) {
        that.MasterDataSyncFlag = true;
        setTimeout(() => {
          if (that.MasterData) {
            if (this.Options.showorderasc == "1") {
              if (that.MasterData.length > 30) {
                //that.MasterDataDisplay = that.MasterData.slice(0, 30);
                that.MasterDataDisplay = that.MasterData.slice(that.MasterData.length - 30);
              } else {
                that.MasterDataDisplay = that.MasterData.slice(0);
              }
              setTimeout(() => {
                that.$refs.xTableCollect.scrollToRow(that.MasterDataDisplay[that.MasterDataDisplay.length - 1]);
                that.$refs.xTableCollect.setCurrentRow(that.MasterDataDisplay[that.MasterDataDisplay.length - 1]);
              }, 1);
            } else {
              that.MasterDataDisplay = that.MasterData.slice(0, 30);
            }
          }
          that.MasterDataSyncFlag = false;
        }, 500);
      }

      let cticks = new Date().getTime();
      that.lastMasterChangeFlag = cticks;
      setTimeout(() => {
        if (that.lastMasterChangeFlag == cticks) {
          if (that.MasterData) that.MasterDataDisplay = that.MasterData.slice(0);
          that.collectbarcodeholder = "请扫描条码...";
          let barcodeinput = document.getElementById("collectbarcodeinput");
          if (barcodeinput) {
            barcodeinput.className = "el-input__inner";
          }
          if (this.Options.showorderasc == "1") {
            setTimeout(() => {
              that.$refs.xTableCollect.scrollToRow(that.MasterDataDisplay[that.MasterDataDisplay.length - 1]);
              that.$refs.xTableCollect.setCurrentRow(that.MasterDataDisplay[that.MasterDataDisplay.length - 1]);
            }, 1);
          }
        } else {
          // console.log("pass...", cticks, that.lastMasterChangeFlag);
        }
        that.MasterDataSyncFlag = false;
      }, 2000);
    },
  },
  created() {
    let syncstr = this.$tool.getLocalConfig("lis310_async");
    if (syncstr) {
      this.isasync = syncstr == "Y";
    }
    let showseq = this.$tool.getLocalConfig("lis310_showseq");
    if (showseq) {
      this.showseq = showseq == "1";
    }
  },
  methods: {
    showseqChange() {
      this.$tool.setLocalConfig("lis310_showseq", this.showseq ? "1" : "0");
    },
    forbidinput() {
      if (this.onlyclickinputday) {
        document.activeElement.blur();
      }
    },
    //处理扫码
    CollectBarcode(e) {
      let that = this;
      let barcodestr = e.target.value;
      e.target.value = "";

      if (barcodestr.length == 0 || barcodestr == that.lasttxtbarcode) {
        return false;
      }
      that.lasttxtbarcode = barcodestr;
      setTimeout(() => {
        // 1秒以后再扫就要做出反应了
        that.lasttxtbarcode = "";
      }, 1000);
      setTimeout(() => {
        if (that.Options.batchinputmustconfirm == "1" && that.collectmustconfirm) {
          that.ValidateBarcode(barcodestr).then(() => {
            that.CollectBarcodeAction(barcodestr);
          });
        } else {
          that.CollectBarcodeAction(barcodestr);
        }
      }, 1);
    },
    CollectBarcodeAction(barcodestr) {
      let that = this;
      if (barcodestr) {
        if (that.batchbarcodeonlytoday == "1") {
          //that.collectselectdate = XE.clone(that.Options.sysdate + " 00:00:00", true);
          that.selectdate = XE.clone(that.Options.sysdate + " 00:00:00", true);
          if (that.collectselectdate != that.selectdate) {
            that.$alert("核收只能核收到今天!", "错误");
            return;
          }
        }

        if (that.isasync) {
          that.GetNextSpecno(that).then((specno) => {
            // sflag状态说明： 0-表示状态完成，这样同步的也直接兼容了， 1-表示刚刚加入，等待处理中，-1-表示错误 ，2-表示错误已读，   其他状态待扩充
            let csampleno = that.collectsampleno; //需要获取到现在的sampleno
            if (this.Options.showorderasc == "1") {
              that.MasterData.push({ sampleno: specno, barcode: barcodestr, csampleno: specno, emer_flag: 0, sflag: 1 });
            } else {
              that.MasterData.splice(0, 0, { sampleno: specno, barcode: barcodestr, csampleno: specno, emer_flag: 0, sflag: 1 });
            }
            // console.log("masterdata", that.MasterData);
          });
        } else {
          let csamplenosync = that.collectsampleno;
          that.SetBarCodeInputReadonlyOn();
          that.collectbarcodeholder = barcodestr + "  正在处理......";
          that.BarCodeToServer(that, barcodestr, csamplenosync)
            .then((res) => {
              that.BarCodeServerBack(that, barcodestr, csamplenosync, res, false);
            })
            .catch((error) => {
              that.SetBarCodeInputReadonlyOff();
            });
        }
      }
    },
    //异步循环处理已经扫进来的条码
    DealBarCode(that) {
      let dealitem = that.MasterData.find((eitem) => eitem.sflag == 1);
      if (!dealitem) {
        that.timeoutrunning = false;
        return;
      }
      let barcodeinput = document.getElementById("collectbarcodeinput");
      that.collectbarcodeholder = "正在处理" + dealitem.barcode;
      if (barcodeinput) {
        barcodeinput.className = "el-input__inner barcoderunning";
      }
      that.BarCodeToServer(that, dealitem.barcode, dealitem.csampleno)
        .then((response) => {
          that.BarCodeServerBack(that, dealitem.barcode, dealitem.csampleno, response, true);
        })
        .catch((error) => {
          console.log("error:", error);
          that.$confirm("出现错误：" + JSON.stringify(error), {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => { })
            .catch(() => { });
        })
        .finally(() => {
          //检查是否还有未处理的
          let nodealindex = that.MasterData.findIndex((eitem) => eitem.sflag == 1);
          if (nodealindex >= 0) {
            //console.log("continuing...", nodealindex);
            setTimeout(() => {
              that.DealBarCode(that);
            }, 100);
          } else {
            // console.log("exittimeout");
            that.timeoutrunning = false;
          }
        });
    },
    //发送条码请求到服务器
    BarCodeToServer(that, barcodestr, csampleno) {
      that.$pub.Log("核收条码请求开始");
      return that.$tool.request({
        url: "LIS/LIS3/LIS310",
        method: "post",
        data: {
          action: "inputbarcode",
          rptunitid: that.collectrptunitid,
          barcode: barcodestr,
          sampledate: that.collectselectdate,
          sampleno: csampleno,
          reportuser: that.exactusernoreport,
          isreceive: 1,
          specimen_code: that.CollectSpecType,
          alertcannoitem: that.alertcannoitem ? "1" : "0",
        },
      });
    },
    async BarCodeServerBack(that, barcodestr, csampleno, res, t_issync) {
      // console.log("res", res);
      that.SetBarCodeInputReadonlyOff();
      let processeditem = -1;
      //不管是不是快扫异步，都要取转换过后的条码
      if (res.report && res.report.barcode) {
        barcodestr = res.report.barcode;
      }
      if (t_issync) {
        // console.log("res", res);
        // 条码可能在后台经过条码转换规则变成了另外一个条码，这里不能再直接找了
        processeditem = that.MasterData.findIndex((e) => e.sampleno == csampleno);
      } else {
        that.$pub.Log("核收条码请求结束");
      }
      if (res.flag == 1) {
        if (t_issync) {
          if (processeditem >= 0) {
            that.MasterData[processeditem] = res.report;
            that.MasterData[processeditem].sflag = 0;
            that.MasterData = that.MasterData.slice(0);
          }
        } else {
          that.$pub.Log("核收条码插入开始");
          that.collectbarcodeholder = barcodestr + " 成功";
          //如果该条码号产生了多个标本号时
          if (res.reports && res.reports.length > 1) {
            that.multiplereportflag = true;
            res.reports.forEach((item) => {
              if (this.Options.showorderasc == "1") {
                that.MasterData.push(item);
                setTimeout(() => {
                  that.$refs.xTableCollect.scrollToRow(item);
                  that.$refs.xTableCollect.setCurrentRow(item);
                }, 1);
              } else {
                that.MasterData.splice(0, 0, item);
                that.$refs.xTableCollect.setCurrentRow(item);
              }
            });
            that.previousPatients = res.reports;
          } else {
            that.multiplereportflag = false;
            if (this.Options.showorderasc == "1") {
              that.MasterData.push(res.report);
              setTimeout(() => {
                that.$refs.xTableCollect.scrollToRow(res.report);
                that.$refs.xTableCollect.setCurrentRow(res.report);
              }, 1);
            } else {
              that.MasterData.splice(0, 0, res.report);
              that.$refs.xTableCollect.setCurrentRow(res.report);
            }
            that.previousPatient = res.report;
          }
          that.$pub.Log("核收条码插入结束");
          that.collectsampleno = that.useautobarcode ? "" : res.nextsmpno;
          that.CollectNum = that.MasterData.length;
          if (res.othermsg && res.othermsg.showMsg != null && res.othermsg.showMsg.length > 0) {
            await that.showlistmsg(res.othermsg.showMsg);
          }
        }
        if (that.Options.inputprintgermsheet > 0) {
          if (that.Options.germsheetid > 0) {
            if (res.report && res.report.reportid) {
              that.$pub.printgermsheet(that, res.report.reportid, that.Options.germsheetid, "1");
            }
          } else {
            that.$message.error("没有维护细菌流程单样式！");
          }
        }
        //添加录入条码后自动打印条码的判断
        if (res.barcode && res.barcodeprintcount && res.barcodeprintcount > 0) {
          for (let i = 0; i < res.barcodeprintcount; i++) {
            this.RePrintBarcode(res.barcode);
          }
        }
        this.$emit("IsSelectPrint", res.barcode, res.report.pat_typecode);
        //end
      } else {
        if (t_issync) {
          if (processeditem >= 0) {
            while (processeditem >= 0) {
              if (res.report) {
                that.MasterData[processeditem].reportid = res.report.reportid;
                that.MasterData[processeditem].emer_flag = res.report.emer_flag;
                that.MasterData[processeditem].pat_name = res.report.pat_name;
                that.MasterData[processeditem].pat_no = res.report.pat_no;
                that.MasterData[processeditem].specimen_codename = res.report.specimen_codename;
                that.MasterData[processeditem].req_reason = res.report.req_reason;
                that.MasterData[processeditem].req_deptnoname = res.report.req_deptnoname;
                that.MasterData[processeditem].req_bedno = res.report.req_bedno;
              }
              that.MasterData[processeditem].barcode = barcodestr;
              that.MasterData[processeditem].sampleno = csampleno;
              that.MasterData[processeditem].sflag = -1; // 此处可以更精细化
              that.MasterData[processeditem].res = { msg: res.msg, flag: res.flag, report: res.report };
              var msgs = "";
              if (res.msg.showMsg.length > 0) msgs = res.msg.showMsg[0].content;
              if (res.msg.confirmDefYesMsg.length > 0) msgs = res.msg.confirmDefYesMsg[0].content;
              if (res.msg.confirmDefNoMsg.length > 0) msgs = res.msg.confirmDefNoMsg[0].content;
              if (res.msg.errorMsg.length > 0) msgs = res.msg.errorMsg[0].content;
              that.MasterData[processeditem].pat_name = msgs.replace(new RegExp("<br/>", 'g'), " ");
              that.MasterData[processeditem].flag = res.flag;
              that.CollectErrNum += 1;
              processeditem = that.MasterData.findIndex((e) => e.barcode == res.barcode && e.sampleno == res.sampleno && e.sflag == 1);
            }
            that.MasterData = that.MasterData.slice(0);
          }
        } else {
          that.temppreviousPatient = res.report;
          if (res.reports && res.reports.length > 1) {
            that.temppreviousPatients = res.reports;
          }
          that.$refs.collectbarcodeinput.blur();
          that.collectbarcodeholder = "请扫描条码";
          if (that.useautobarcode && csampleno == "") {
            csampleno = res.sampleno;
          }
          that.DealEvent(that, barcodestr, res, csampleno);
        }
      }
    },
    //从服务器返回的结果处理
    DealEvent(that, barcodestr, res, csampleno) {
      that.$parent
        .ErrorListDeal(res.msg, res.flag, 0)
        .then(() => {
          that.CollectSave(that, 1, barcodestr, csampleno, res); //type=0 错误消息 type=1 确认消息
        })
        .catch(() => {
          that.CollectSave(that, 0, barcodestr, csampleno, res);
        });
    },
    RePrintBarcode(barcode) {
      console.log("bbb", barcode, this.Options.lisbarstyle);
      if (barcode && barcode != "") {
        if (!this.Options.lisbarstyle || this.Options.lisbarstyle == "") {
          this.$alert("没有维护条码样式!", "提示");
        } else {
          this.$pub.printbarcode(this, barcode, "1", this.Options.lisbarstyle, "", "1");
        }
      }
    },
    async showlistmsg(showMsgLst) {
      if (showMsgLst) {
        let id = 0;
        while (id < showMsgLst.length) {
          try {
            let content = showMsgLst[id].content;
            if (content) {
              let title = showMsgLst[id].title;
              if (!title) {
                title = "提示";
              }
              await this.$alert(content, title);
            }
          }
          catch { }
          id++;
        }
      }
    },
    async CollectSave(that, type, barcodestr, csampleno, response) {
      //type=0 错误消息 type=1 确认消息
      var othermsg = response.othermsg;
      let index = that.MasterData.findIndex((eitem) => eitem.barcode == barcodestr && eitem.sampleno == csampleno);
      //如果确认的条码号有多个标本标号
      let sampleInfolist = [];
      if (response.sampleInfos && response.sampleInfos.length > 1) {
        sampleInfolist = response.sampleInfos;
      }
      if (type) {
        try {
          //TODO 条码录入
          let res = await that.$tool
            .request({
              url: "LIS/LIS3/LIS310",
              method: "post",
              data: {
                action: "savecollectbarcode",
                rptunitid: that.collectrptunitid,
                barcode: barcodestr,
                sampledate: that.collectselectdate,
                sampleno: csampleno,
                reportuser: that.exactusernoreport,
                specimen_code: that.CollectSpecType,
                alertcannoitem: that.alertcannoitem ? "1" : "0",
                sampleInfos: sampleInfolist,
              },
            })
          if (res.flag == "1") {
            if (that.isasync) {
              that.MasterData[index] = that.MasterData[index].res.report;
              if (index && index > -1) that.MasterData[index].sflag = 0; // mod by yangliang 2021-05-23  应该改成0 表示完成了吧
              that.MasterData = that.MasterData.slice(0);
              that.CollectErrNum -= 1;
              let row = that.$refs.xTableCollect.tableFullData[index];
              that.$refs.xTableCollect.setCurrentRow(row);
            } else {
              //如果该条码号产生了多个标本号时
              if (res.reportidlist && res.reportidlist.length > 1) {
                that.multiplereportflag = true;
                res.reportidlist.forEach((item, reportindex) => {
                  that.temppreviousPatients[reportindex].reportid = item;
                  that.MasterData.splice(0, 0, that.temppreviousPatients[reportindex]);
                  that.$refs.xTableCollect.setCurrentRow(that.temppreviousPatients[reportindex]);
                });
                that.previousPatients = that.temppreviousPatients;
              } else {
                that.multiplereportflag = false;
                that.temppreviousPatient.reportid = res.reportid;
                that.previousPatient = that.temppreviousPatient;
                that.MasterData.splice(0, 0, that.temppreviousPatient);
                that.$refs.xTableCollect.setCurrentRow(that.temppreviousPatient);
              }
              that.collectsampleno = that.useautobarcode ? "" : res.nextsmpno;
              that.CollectNum = that.MasterData.length;
              that.$nextTick(() => {
                that.$refs.collectbarcodeinput.focus();
              });
              if (othermsg && othermsg.showMsg != null && othermsg.showMsg.length > 0) {
                await that.showlistmsg(othermsg.showMsg);
              }
            }
            try {
              if (that.Options.inputprintgermsheet > 0) {
                if (that.Options.germsheetid > 0) {
                  if (res && res.reportid) {
                    that.$pub.printgermsheet(that, res.reportid, that.Options.germsheetid, "1");
                  }
                } else {
                  that.$message.error("没有维护细菌流程单样式！");
                }
              }
              //添加录入条码后自动打印条码的判断
              if (response.barcode && response.barcodeprintcount && response.barcodeprintcount > 0) {
                for (let i = 0; i < response.barcodeprintcount; i++) {
                  this.RePrintBarcode(response.barcode);
                }
              }
              this.$emit("IsSelectPrint", response.barcode, response.report.pat_typecode);
              //end
            } catch (e) {
              console.log("ee", e);
            }
          } else {
            let msg = res.msg;
            if (!msg) {
              msg = "条码核收失败，核收过程发生错误！";
            }
            that.$alert(msg).then(() => {
              if (index && index > -1) that.MasterData[index].sflag = 2;
              that.CollectErrNum -= 1;
              that.$nextTick(() => {
                that.$refs.collectbarcodeinput.focus();
              });
            });
          }
        }
        catch (error) {
          console.log("errorerror", error);
          that.$alert("条码核收失败，核收过程发生异常！").then(() => { });
        };
      } else {
        if (this.isasync) {
          that.MasterData[index].sflag = 2;
          that.CollectErrNum -= 1;
          let row = that.$refs.xTableCollect.tableFullData[index];
          that.$refs.xTableCollect.setCurrentRow(that.MasterData[index]);
          that.$nextTick(() => {
            that.$refs.collectbarcodeinput.focus();
          });
        } else {
          that.$refs.collectbarcodeinput.focus();
        }
      }
    },

    //核收项目，从父级调用，入口
    CollectDeal(prgno, rptunitid, selectdate, specno, batchbarcodeonlytoday, options) {
      let that = this;
      that.PRGNO = prgno;
      that.batchbarcodeonlytoday = batchbarcodeonlytoday;
      that.onlyclickinputday = options.batchinputdaymustclick == "1";
      this.Options = options;
      if (this.Options.inputmsgnofinish == "1") that.alertcannoitem = true;
      else that.alertcannoitem = false;
      //that.BeforePatient = JSON.parse(JSON.stringify(PatientInfo));
      that.CollectSpecType = "";
      //batchbarcodeonlytoday 核收只能核收到当天
      that.$tool
        .request({
          url: "LIS/LIS3/LIS310",
          method: "post",
          data: {
            action: "getreceivesampleno",
            rptunitid: rptunitid,
            sampledate: selectdate,
            sampleno: specno,
          },
        })
        .then((res) => {
          if (res.flag == 1) {
            that.dialogCollectVisible = true;
            that.collectrptunitid = rptunitid - 0;
            that.collectselectdate = XE.clone(selectdate, true);
            that.useautobarcode = res.useautobarcode == 1;
            that.collectsampleno = that.useautobarcode ? "" : res.sampleno;
            that.dialogTitle = that.useautobarcode ? "标本核收(按申请项目自动编号)" : "标本批量核收";

            if (res.batchinputshownoseg > 0) {
              that.batchinputshownoseg = true;
              that.tableColumnBatch = [];
              for (let i = 0; i < res.RData.Cols.length; i++) {
                if (res.RData.Cols[i].field == "pat_typename" || res.RData.Cols[i].field == "specimen_name") that.tableColumnBatch.push({ field: res.RData.Cols[i].field, title: res.RData.Cols[i].title, width: "120px" });
                else that.tableColumnBatch.push({ field: res.RData.Cols[i].field, title: res.RData.Cols[i].title, width: "80px" });
              }
              that.tableDataBatch = res.RData.Data;
            } else {
              that.batchinputshownoseg = false;
            }
            that.CollectNum = 0;
            that.CollectErrNum = 0;
            that.$nextTick(() => {
              that.$refs.collectbarcodeinput.focus();
            });
          } else {
            that.$parent.ErrorListDeal(res.msg, res.flag);
          }
        });
    },
    //核收窗口号段双击事件
    CollectDblClick({ row }) {
      let that = this;
      console.log("dbclick");
      that.$tool
        .request({
          url: "LIS/LIS3/LIS310",
          method: "post",
          data: {
            action: "getmaxsampleno",
            startno: row.startno,
            endno: row.endno,
            sampledate: that.collectselectdate,
            rptunitid: that.collectrptunitid,
          },
        })
        .then((res) => {
          if (res.flag == "1") {
            that.collectsampleno = that.useautobarcode ? "" : res.specno;
          } else {
            console.log("msg2", res.msg);
            that.$alert(res.msg, "错误");
          }
        });
    },
    //核收窗口关闭跳回原始选择界面
    CollectClose() {
      let that = this;
      let row = that.MasterData.find((e) => e.sflag == -1);
      if (!row) {
        if (that.rptunitid == that.BeforePatient.rptunitid && that.selectdate == that.BeforePatient.sampledate) {
          that.specno = that.BeforePatient.sampleno + "";
          if (!that.specno) that.specno = "1";
          that.$parent.QueryList(1);
        } else {
          that.$parent.QueryList(1);
        }
        that.previousPatients = [];
        that.previousPatient = {};
        that.MasterData = [];
        that.dialogCollectVisible = false;
        that.$emit("update:visible", false);
      } else {
        that.$confirm("仍有错误消息未处理，您确定要放弃处理吗？", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            if (that.rptunitid == that.BeforePatient.rptunitid && that.selectdate == that.BeforePatient.sampledate) {
              that.specno = that.BeforePatient.sampleno + "";
              if (!that.specno) that.specno = "1";
              that.$parent.QueryList(1);
            } else {
              that.$parent.QueryList(1);
            }
            that.previousPatients = [];
            that.previousPatient = {};
            that.MasterData = [];
            that.dialogCollectVisible = false;
            that.$emit("update:visible", false);
          })
          .catch(() => {
            that.$emit("update:visible", true);
            that.dialogCollectVisible = true;
          });
      }
    },

    //报告单元改变
    collectrptunitidchange(rptunitid) {
      let that = this;
      if (rptunitid == that.collectrptunitid) return;
      that.MasterData = [];
      that.previousPatient = {};
      that.previousPatients = [];
      that.$tool
        .request({
          url: "LIS/LIS3/LIS310",
          method: "post",
          data: {
            action: "getreceivesampleno",
            rptunitid: rptunitid,
            sampledate: that.collectselectdate,
            sampleno: "1",
          },
        })
        .then((res) => {
          if (res.flag == 1) {
            that.useautobarcode = res.useautobarcode == 1;
            that.collectsampleno = that.useautobarcode ? "" : res.sampleno;
            that.dialogTitle = that.useautobarcode ? "标本核收(按报告单元自动编号)" : "标本批量核收";
            if (res.batchinputshownoseg > 0) {
              that.batchinputshownoseg = true;
              that.tableColumnBatch = [];
              for (let i = 0; i < res.RData.Cols.length; i++) {
                if (res.RData.Cols[i].field == "pat_typename" || res.RData.Cols[i].field == "specimen_name") that.tableColumnBatch.push({ field: res.RData.Cols[i].field, title: res.RData.Cols[i].title, width: "120px" });
                else that.tableColumnBatch.push({ field: res.RData.Cols[i].field, title: res.RData.Cols[i].title, width: "80px" });
              }
              that.tableDataBatch = res.RData.Data;
            } else {
              that.batchinputshownoseg = false;
            }
            that.CollectNum = 0;
            that.CollectErrNum = 0;
          } else {
            that.$parent.ErrorListDeal(res.msg, res.flag);
          }
        });
      that.$nextTick(() => {
        that.$refs.collectbarcodeinput.focus();
      });
    },

    //删除
    CollectDel() {
      let that = this;
      var rows = that.$refs.xTableCollect.getSelectRecords();
      if (rows.length == 0) {
        that.$alert("未选中要删除的标本!", "提示");
        return;
      }
      that.$confirm("你确定要删除选中的标本吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        focusCancelButton: true,
        closeOnClickModal: false,
        type: "warning",
      }).then(() => {
        var index0 = that.$refs.xTableCollect.getRowIndex(rows[0]);
        var result = [];
        var errnum = 0;
        for (let i = 0; i < rows.length; i++) {
          if (result.findIndex((item) => item == rows[i]) < 0) {
            result.push(rows[i].reportid);
            let Mindex = that.MasterData.findIndex((m) => m.reportid == rows[i].reportid);
            if (Mindex >= 0) {
              that.MasterData.splice(Mindex, 1);
              if (rows[i].sflag == -1) errnum += 1;
            }
            that.CollectDelAction(rows[i].reportid);
          }
        }
        if (index0 == 0) that.collectsampleno = that.useautobarcode ? "" : rows[0].sampleno;
        that.CollectNum -= result.length;
        that.CollectErrNum -= errnum;
      });
    },
    CollectDelAction(id) {
      let that = this;
      that.$tool
        .request({
          url: "LIS/LIS3/LIS310",
          method: "post",
          data: {
            action: "deletereport",
            reportid: id,
            mode: "1",
          },
        })
        .then((res) => {
          if (res.Item1 == 1) {
            that.$message({
              message: "删除成功",
              type: "success",
            });
          } else {
            that.$parent.ErrorListDeal(res.Item2, res.Item1);
          }
        });
    },
    async samplenochg(sampleno) {
      if (!!sampleno) {
        this.collectsampleno = sampleno;
      }
    },
    async SampleNoChange() {
      this.$parent.specno = this.collectsampleno;
      await this.$parent.SpecNoChange();
      this.$nextTick(() => {
        this.$refs.collectbarcodeinput.focus();
      });
    },
    DateBackGround() {
      var datenow = this.Options.sysdate + " 00:00:00";
      if (datenow > this.collectselectdate) {
        return "beforedate";
      } else if (datenow < this.collectselectdate) {
        return "overdate";
      } else {
        return "basecolor";
      }
    },
    //上一个下一个
    CollectMove(type) {
      let that = this;
      //type=1下一个 type=0上一个
      if (type > 0) {
        that.GetNextSpecno(that).then(() => {
          let row = that.MasterData.find((item) => item.sampleno == that.collectsampleno);
          if (row) {
            that.$refs.xTableCollect.setCurrentRow(row);
          }
          that.SampleNoChange();
        });
      } else {
        that.GetLastSpecno(that).then(() => {
          var row = that.MasterData.find((item) => item.sampleno == that.collectsampleno);
          if (row) {
            that.$refs.xTableCollect.setCurrentRow(row);
          }
          that.SampleNoChange();
        });
      }
    },
    GetNextSpecno(that) {
      return new Promise((s, f) => {
        var oldno = this.collectsampleno;
        var specstr = this.$pub.GetNextSpecno(this.collectsampleno);
        this.collectsampleno = specstr;
        s(oldno);
      });
    },
    GetLastSpecno(that) {
      return new Promise((s, f) => {
        var oldno = this.collectsampleno;
        var specstr = this.$pub.GetLastSpecno(this.collectsampleno);
        this.collectsampleno = specstr;
        s(oldno);
      });
    },

    //主表根据sflag显示不同颜色
    xTableCollect_rowClass({ seq, row, rowIndex, $rowIndex }) {
      if (row.sflag) {
        switch (row.sflag) {
          case 1:
            return "processingcls";
          case -1:
            return "errocls parent-row";
          case 2:
            return "erroalreadyread parent-row";
        }
      }
    },
    //主表双击事件
    xTableCollect_dbclick(param, event) {
      let { row, rowIndex, $rowIndex, column, columnIndex, $columnIndex, cell } = param;
      // console.log("event", param, event, rowIndex);
      let that = this;
      if (row.sflag && row.sflag == -1) {
        that.DealEvent(that, row.barcode, row.res, row.sampleno);
      }
    },
    //合并单元格
    colspanMethod({ row, rowIndex, column, columnIndex, data }) {
      if (row.sflag == -1 || row.sflag == 2) {
        if (columnIndex === 4) {
          return {
            rowspan: 1,
            colspan: 6,
          };
        } else if (columnIndex === 5 || columnIndex === 6 || columnIndex === 7 || columnIndex === 8 || columnIndex === 9) {
          return {
            rowspan: 0,
            colspan: 0,
          };
        }
      }
    },
    //核收前确认提醒
    ValidateBarcode(barcode) {
      return new Promise((s, f) => {
        let that = this;
        that.$tool
          .request({
            url: "LIS/LIS3/LIS310",
            method: "post",
            data: {
              action: "reqdetailbybarcode",
              barcode: barcode,
            },
          })
          .then((res) => {
            if (res.errcode == "1") {
              that.$confirm("当前核收条码号: " + res.showbarcode + " 姓名: " + res.patname + " 标本类型: " + res.specimen + " 申请项目: " + res.reqitem, "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                focusCancelButton: true,
                closeOnClickModal: false,
                dangerouslyUseHTMLString: true,
                type: "warning",
              })
                .then(() => {
                  s();
                })
                .catch(() => {
                  f();
                });
            } else {
              this.$alert(res.errmsg, "提示");
              f();
            }
          })
          .catch((err) => {
            f();
          });
      });
    },
    //主表点击事件
    RowClick({ row }) {
      this.previousPatient = row;
    },
    SetBarCodeInputReadonlyOn() {
      let barcodeinput = document.getElementById("collectbarcodeinput");
      if (barcodeinput) {
        barcodeinput.setAttribute("readOnly", "true");
        barcodeinput.className = "el-input__inner barcoderunning";
      }
    },
    SetBarCodeInputReadonlyOff() {
      let barcodeinput = document.getElementById("collectbarcodeinput");
      if (barcodeinput) {
        barcodeinput.removeAttribute("readOnly");
        barcodeinput.className = "el-input__inner";
      }
    },
    //打印核收条码清单
    PrintBarcode() {
      var data = XE.clone(this.$refs.xTableCollect.afterFullData, true);
      if (data.length == 0) {
        this.$alert("没有待打印的核收标本!", "提示");
        return;
      }
      var rptunitname = "";
      var unit = this.$refs.collectrptunit.fulldata.Data.find((item) => item.rptunitid == this.collectrptunitid);
      if (unit) rptunitname = unit.rptunitname;
      var sampledate = XE.toDateString(this.collectselectdate, "yyyy-MM-dd");
      let column = this.$refs.xTableCollect.getTableColumn().tableColumn;
      column.push({ property: "rptunitname", title: "报告单元" });
      column.push({ property: "sampledate", title: "核收日期" });
      for (let i = 0; i < data.length; i++) {
        data[i].rptunitname = rptunitname;
        data[i].sampledate = sampledate;
        if (data[i].emer_flag == "1") data[i].emer_flag = "急";
        else data[i].emer_flag = "";
      }
      let str = JSON.stringify(this.$pub.InitColumn(column));
      str += "\r";
      str += JSON.stringify(data);
      let sql = btoa(encodeURIComponent(str));
      jsObj.PrintCustomJsonReport(this.Options.inputsampleliststyle, sql, this.$tool.getSession(this.$tool.loginuserno), "打印清单", "");
      //jsObj.SetCustomJsonPrintConfig(this.Options.inputsampleliststyle, sql, this.$tool.getSession(this.$tool.loginuserno), "打印清单");
    },
  },
};
</script>
<style scoped>
table tr td:nth-child(odd) {
  text-align: right;
  white-space: nowrap;
}

table tr td:nth-child(even) {
  text-align: left;
}

table tr td:nth-child(1) {
  width: 80px;
}

table {
  font-size: 12px;
  border-collapse: separate;
  /* border-spacing: 5px; */
}

/deep/.processingcls td {
  color: #1087ba;
}

/deep/.errocls td {
  color: red;
}

/deep/.erroalreadyread td {
  color: #0a5fb4;
}

.barcoderunning::-webkit-input-placeholder {
  color: #ff0000;
}

/deep/ .parent-row .vxe-cell {
  width: 100% !important;
}

::v-deep .collectspec .el-input__inner {
  font-weight: bold;
  color: blue;
  font-size: 18px;
}

.parent-row-name {
  display: inline-block;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
}

.top-sample-info {
  font-weight: bold;
  font-size: 13px;
  margin-right: 30px;
}

::v-deep .collectbtntable .el-checkbox__label {
  padding-left: 2px;
}</style>
